package edu.huangke.convert;

import org.springframework.core.convert.converter.Converter;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConverter implements Converter<String, Date> {

    @Override
    public Date convert(String source) {
        String dateFormat = "yyyy-MM-dd";
        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);

        Date date = null;
        try {
            date = sdf.parse(source);
        }catch (Exception e) {
            e.printStackTrace();
            System.out.println("请采取正确的格式: " + dateFormat);
        }
        return date;
    }
}
